package com.saikuo.service.controller;

import com.saikuo.service.api.ApiResultModel;
import com.saikuo.service.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chenzhuo on 16/7/24.
 */
@Api(value = "用户相关接口", description = "注册、登陆，收货地址等")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "获取验证码(codeType:1-注册;2-修改密码;3-快捷登陆)")
    @RequestMapping(value = "/get/verifyCode", method = RequestMethod.GET)
    public ApiResultModel getVerifyCode(@RequestParam String mobile,
                                        @RequestParam int codeType) {
        return userService.sendVerifyCode(mobile, codeType);
    }

    @ApiOperation(value = "手机号注册")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ApiResultModel register(@RequestParam String verifyCode,
                                   @RequestParam String mobile,
                                   @RequestParam String password) {
        return userService.register(verifyCode, mobile, password);
    }

    @ApiOperation(value = "手机密码登陆")
    @RequestMapping(value = "/pwdLogin", method = RequestMethod.GET)
    public ApiResultModel pwdLogin(@RequestParam String mobile,
                                   @RequestParam String password) {
        return userService.pwdLogin(mobile, password);
    }

    @ApiOperation(value = "手机验证码快捷登陆")
    @RequestMapping(value = "/codeLogin", method = RequestMethod.GET)
    public ApiResultModel codeLogin(@RequestParam String mobile,
                                    @RequestParam String verifyCode) {
        return userService.codeLogin(mobile, verifyCode);
    }

    @ApiOperation(value = "忘记密码")
    @RequestMapping(value = "/forget/password", method = RequestMethod.POST)
    public ApiResultModel forgetPassword(@RequestParam String verifyCode,
                                         @RequestParam String mobile,
                                         @RequestParam String newPassword) {
        return userService.forgetPassword(verifyCode, mobile, newPassword);
    }

    @ApiOperation(value = "修改密码")
    @RequestMapping(value = "/change/password", method = RequestMethod.POST)
    public ApiResultModel changeLoginPassword(@RequestParam String oldPassword,
                                              @RequestParam String newPassword,
                                              @RequestParam int userId) {
        return userService.changePassword(userId, oldPassword, newPassword);
    }

    @ApiOperation(value = "添加收货地址")
    @RequestMapping(value = "/addUserAddress", method = RequestMethod.POST)
    public ApiResultModel addUserAddress(@RequestParam int userId,
                                         @RequestParam String mobile, @RequestParam String address, @RequestParam String name, @RequestParam Double lat, @RequestParam Double lng, @RequestParam String cityCode, @RequestParam String areaCode) {
        return userService.addUserAddress(userId, mobile, address, name, lat, lng, cityCode, areaCode);
    }

    @ApiOperation(value = "修改收货地址")
    @RequestMapping(value = "/updateUserAddress", method = RequestMethod.POST)
    public ApiResultModel updateUserAddress(@RequestParam int id,
                                            @RequestParam String mobile, @RequestParam String address, @RequestParam String name, @RequestParam Double lat, @RequestParam Double lng, @RequestParam String cityCode, @RequestParam String areaCode) {
        return userService.updateUserAddress(id, mobile, address, name, lat, lng, cityCode, areaCode);
    }

    @ApiOperation(value = "获取一条收货地址")
    @RequestMapping(value = "/getUserAddressById", method = RequestMethod.GET)
    public ApiResultModel getUserAddressById(@RequestParam int id) {
        return userService.getUserAddressById(id);
    }

    @ApiOperation(value = "获取用户收货地址列表")
    @RequestMapping(value = "/getUserAddressByUserId", method = RequestMethod.GET)
    public ApiResultModel getUserAddressByUserId(@RequestParam int userId) {
        return userService.getUserAddressByUserId(userId);
    }

    @ApiOperation(value = "删除一条收货地址")
    @RequestMapping(value = "/deleteUserAddressById", method = RequestMethod.GET)
    public ApiResultModel deleteUserAddressById(@RequestParam int id) {
        return userService.deleteUserAddressById(id);
    }

    @ApiOperation(value = "用户意见反馈")
    @RequestMapping(value = "/createFeedBack", method = RequestMethod.POST)
    public ApiResultModel createFeedBack(@RequestParam int userId,
                                         @RequestParam String message) {
        return userService.createFeedBack(userId,message);
    }
}
